﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'roleAdd')
	BEGIN
		DROP  Procedure  roleAdd
	END
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[roleAdd] 
	-- Add the parameters for the stored procedure here
	@role_name VARCHAR(50),
	@role_desc VARCHAR(255),
	@app_id INT
AS	
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF EXISTS(	SELECT lit_rol_id 
				FROM lit_rol 
				WHERE lit_rol_nombre = @role_name 
				AND lit_aplicacion_id = @app_id )
	BEGIN
		SELECT 0;
	END
    ELSE BEGIN
		INSERT INTO lit_rol (lit_rol_nombre, lit_rol_desc, lit_aplicacion_id)
		VALUES (@role_name, @role_desc, @app_id)
		SELECT @@Identity;
	END
END
GO